
<%@ page import="org.codehaus.groovy.grails.commons.ConfigurationHolder"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <link rel="apple-touch-icon" href="/easyTracker/images/logo-medium.png"/>
</head>
<body>

<div id="fb-root"></div>
<script type="text/javascript">
    var uid , accessToken;
    var status ;
   	window.fbAsyncInit = function() {
	    FB.init({
	      appId      : '${ConfigurationHolder.config.grails.facebooAppID}', // App ID
	  //    channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
	      status     : true, // check login status
	      cookie     : true, // enable cookies to allow the server to access the session
	      xfbml      : true  // parse XFBML
	    });
        
	    FB.getLoginStatus(function(response) {
              status = response.status;
			  if (response.status == 'connected') {
			    uid = response.authResponse.userID;
			    accessToken = response.authResponse.accessToken;
			  }
	    });   
    };
   (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
   
  function start(){
        if (status == 'connected') {
            //alert('go to :' + "main?uid=" + uid + "&token=" + accessToken);
			window.location = "main?uid=" + uid + "&token=" + accessToken;
        } else if (status == 'not_authorized'){
            window.location = "/vendingMachine/userProcess/register";
        } else {
            //alert('plz login -> popup the login dialog');
            FB.login(function(response) {
               if (response.authResponse) {
                 /*console.log('Welcome!  Fetching your information.... ');
                 FB.api('/me', function(response) {
                   console.log('Good to see you, ' + response.name + '.');
                 });*/
                 //alert('token:'+response.authResponse.accessToken);
                 window.location = "main?uid=" + response.authResponse.userID + "&token=" + response.authResponse.accessToken;
               } else {
                 //console.log('User cancelled login or did not fully authorize.');
                 alert('User cancelled login or did not fully authorize.');
               }
            });
        }
  }
</script> 

<h1>welcome!!!!!</h1>
<img src="${resource(dir: 'images', file: 'candy-machine-card.jpg')}"/>
<!--<g:link controller="information" action="main"><h1>[START]</h1></g:link>-->
<input type="button" onclick="start()" value="[START]" />
<!--<a href="http://www.learningmovabletype.com/about2.php" 
onclick="window.open('/vendingMachine/userProcess/register/','popup','width=600,height=700,scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=50,top=0'); return false">About</a>-->
</body>
</html>
